package com.spark.check

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentStatePagerAdapter
import android.view.View
import com.spark.common.BaseFragment
import kotlinx.android.synthetic.main.frag_duty_dispath.*

/**
 * 职责分工
 */
class DutyDispatchFragment : BaseFragment() {
    private val tab_titls = mutableListOf("检查要求", "标化资料", "项目评分")
    private lateinit var dutyAdapter: DutyAdapter

    override fun contentResId(): Int {
        return R.layout.frag_duty_dispath
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        iv_back.setOnClickListener { pop() }
        ll_whole_category.setOnClickListener { }

        tab_titls.forEach {
            tabs.addTab(tabs.newTab().setText(it))
        }

        activity?.apply {
            dutyAdapter = DutyAdapter(supportFragmentManager)
            pager.adapter = dutyAdapter
            tabs.setupWithViewPager(pager)
        }
    }
}

class DutyAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
    override fun getItem(position: Int): Fragment {
        return when (position) {
            0 -> DutyDispatchChkRequireFragment.newInstance()
            1 -> DutyDispatchStdDataFragment.newInstance()
            else -> DutyDispatchProjectEvalueFragment.newInstance()
        }
    }

    override fun getCount(): Int {
        return 3
    }


}